//
//  HDAnnotationView.m
//  HDMapKit
//
//  Created by Liuzhuan on 13-4-8.
//  Copyright (c) 2013年 hengdawb. All rights reserved.
//

#import "HDAnnotationView.h"
#import "HDCallOutView.h"
#import <QuartzCore/QuartzCore.h>
#import "HDDeclare.h"
#import "UIView+Extension.h"
//#import "HDScrollLabel.h"

//#import "UIButton+WebCache.h"

@interface HDAnnotationView ()


@end

static NSString *pointHei = @"mapPointHei";
static NSString *pointNor = @"mapPointNor";

@implementation HDAnnotationView

- (id)initWithAnnotation:(HDAnnotation *)annotation animated:(BOOL)animate {
    
	if ((self = [super initWithFrame:CGRectZero])) {
        
        self.annotation = annotation;

        float pinWidth = 30;
        float pinHeight = 30;
        
        self.frame = CGRectMake(0, 0, pinWidth, pinHeight);
        self.center = self.annotation.point;
        self.clipsToBounds = NO;
        [self setBackgroundImage:[UIImage imageNamed:@"pinTest"] forState:UIControlStateNormal];
        [self addTarget:self action:@selector(showCallOut) forControlEvents:UIControlEventTouchUpInside];
        
		if (animate) {
			CABasicAnimation *pindrop = [CABasicAnimation animationWithKeyPath:@"position.y"];
			pindrop.duration       = 0.5f;
			pindrop.fromValue      = [NSNumber numberWithFloat:self.center.y - kScreenHeight];
			pindrop.toValue        = [NSNumber numberWithFloat:self.center.y];
			pindrop.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
			[self.layer addAnimation:pindrop forKey:@"pindrop"];
		}
	}
    
//    NSLog(@"originalFram:%@",NSStringFromCGRect(self.centerImage.frame));
    
	return self;
}

-(void)showCallOut
{
//    [self.myDelegate heighlightAnnotationWith:self];
//    
//    self.transform = CGAffineTransformMakeScale(1.5, 1.5);
}

-(void)showHeigh
{
    self.transform = CGAffineTransformMakeScale(1.5, 1.5);
}

-(void)showNormal
{
    self.transform = CGAffineTransformMakeScale(1.0, 1.0);
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    
	if ([keyPath isEqual:@"contentSize"]) {        
        NSString *biliStr = (NSString*)[object valueForKey:@"zoomScale"];
        float bili = biliStr.floatValue;
        self.center = CGPointMake(self.annotation.point.x*bili, self.annotation.point.y*bili);
        
        //NSLog(@"%@",NSStringFromCGPoint(self.center));
	}
}

@end
